package com.yunding.util;

import com.yunding.constants.SystemConstants;
import com.yunding.redis.RedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *
 * </p>
 *
 * @author 杜奕明
 * @date 2020/1/18
 */
@Component
public class TokenParser {


    @Autowired
    private RedisManager redisManagerTemp;

    private static RedisManager redisManager;


    @PostConstruct
    public void init() {
        redisManager = redisManagerTemp;
    }

    public static Long token2UserIdL(HttpServletRequest request) {
        return Long.valueOf((String) redisManager.get(request.getHeader(SystemConstants.TOKEN)));
    }

    public static String token2UserId(HttpServletRequest request) {
        return String.valueOf(redisManager.get(request.getHeader(SystemConstants.TOKEN)));
    }

}
